package com.android.presenter.info;

import com.android.model.net.HttpObserver;
import com.android.presenter.base.BasePresenter;
import com.android.presenter.iview.IResetAccountPasswordView;
import com.android.model.info.UserModel;
import com.android.util.log.LogUtil;

import retrofit2.Response;

/**
 * 重设密码
 * Created by TenFace on 2018/4/23.
 */

public class ResetAccountPasswordPresenter extends BasePresenter<IResetAccountPasswordView> {
    private static final String TAG = ResetAccountPasswordPresenter.class.getSimpleName();
    private UserModel mUserModel;

    public ResetAccountPasswordPresenter(IResetAccountPasswordView iResetAccountPasswordView) {
        super(iResetAccountPasswordView);
        mUserModel = UserModel.getInstance();
    }

    public void resetAccountPassword(String password,  String token) {
        mUserModel.resetAccountPassword(token, password, new HttpObserver<Response<Void>>() {
            @Override
            public void onSuccess(Response<Void> voidResponse) {
                LogUtil.e(TAG, "重设密码成功");
                if (mIView != null) {
                    mIView.resetPasswordSuccess(voidResponse);
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "失败码：" + errType + "》》信息：" + errMessage);
                if (mIView != null) {
                    mIView.resetPasswordFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
